/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef PARSE_H
#define PARSE_H

#include <Windows.h>
#include <tchar.h>
#include <string>
#include "tokerr.h"

using namespace std;

#define PARSE_DELIM L"!@#$%^&*()_+-=:<>,.?/"

///////////////////////////////////////////////////////////////
// Parse: Parses 
///////////////////////////////////////////////////////////////
class Parse
{
public: // Construction
	Parse()
	{
		Init();
	}

public: // Methods
	void InitBuffer(const wchar_t *buffer) // Initializes buffer
	{
		_buffer = buffer;
		_is_string = false;
		_i = _buffer.begin();
		_is_end = _i == _buffer.end();
	}

	void InitDelim(const wchar_t *delim = PARSE_DELIM) // Initilizes deliminators
	{
		_delim = delim;
	}
	
	void InitComment(const wchar_t com) // Initializes comment
	{
		_comment = com;
	}
public: // Methods
	TokErr Next(); // Parses next word

public: // Methods
	wstring GetBuffer() { return _buffer; }
	wstring GetDelim() { return _delim; }
	wstring GetWord() { return _word; }
	wchar_t GetComment() const { return _comment; }

	bool IsEnd() const { return _is_end; }
	bool IsString() const { return _is_string; }

private: // Methods
	void Init()
	{
		_comment = ';';
		_is_end = _is_string = false;
	}

private: // Methods
	wstring _buffer; // The buffer
	wstring _delim; // Deliminators
	wstring _word; // A word parsed
	wchar_t _comment; // Initializes comment

	wstring::iterator _i; // Pointer to the buffer

	bool _is_end; // At the end of the buffer?
	bool _is_string; // A string?
};
#endif